// Functions associated with the Macrobar class
//-----------------

//-----------------
// Includes libraries and other files
#include "Macrobar.h"
//-----------------

//-----------------
//// CONSTRUCTOR - Macrobar
Macrobar::Macrobar( const int& width, const int& height)
	: BUTTON_WIDTH( 20), BUTTON_HEIGHT( 20)
{
	set_x( 0);
	set_y( height);
	set_width( width);
	set_height( BUTTON_HEIGHT + 10);

	// set the y position to include the menubar's height as well
	int x( 10), y( height+5);
	for( int i( 0); i < BUTTON_ALL; i++, x+=BUTTON_WIDTH)
		set_button_coordinates( i, x, y);
}

//// DESTRUCTOR - ~Menubar
Macrobar::~Macrobar() {}
//-----------------

//-----------------
//// FUNCTION - 
// 
bool Macrobar::mouseover_border( const int& x, const int& y) const {

	return true;
}

//// FUNCTION - mouseover_button
// return true if a button is being cursored over
bool Macrobar::mouseover_button( const int& x, const int& y) {
	// Pre-conditions :- none
	assert( true);

	// run through all the buttons in the array to test if they're under the mouse position
	for( int i( 0); i < BUTTON_ALL; i++) {
		if(( x >= buttons_[i][0]-(BUTTON_WIDTH/2) && x <= buttons_[i][0]+(BUTTON_WIDTH/2)) &&
		   ( y >= buttons_[i][1]-(BUTTON_HEIGHT/2) && y <= buttons_[i][1]+(BUTTON_HEIGHT/2)) )
		   return true;
	}

	// if none of the buttons are under the mouse then return false
	return false;
}

//// FUNCTION - 
// 
void Macrobar::get_button_coordinates( const int& b, int& x, int& y) const {

}

//// FUNCTION - 
// 
void Macrobar::set_button_coordinates( const int& b, const int& x, const int& y) {

}

//// FUNCTION - render
// output the sidebar to the rendering device
void Macrobar::render( LPDIRECT3DDEVICE9 device, const Window& window) {
	// Pre-conditions :- the device must exist
	assert( device != nullptr);

	float x( 0), y( 0), sx( 0), sy( 0);

	// the background images need to be rendered first (i.e. the ones from Toolbar)
	// render the dark background of the macrobar
	x  = (get_x() + (get_width()/2)) / window.get_screen_width();
	y  = (window.get_screen_height() - get_y() - (get_height()/2)) / window.get_screen_height();
	sx = get_width() / window.get_screen_width();
	sy = get_height() / window.get_screen_height();
	orthographic_plane_.render( textures_[TEXTURE_BACKGROUND], x, y, 1.5, sx, sy, 1.0, 100);

	// render the border
	x  = (get_x() + (get_width()/2)) / window.get_screen_width();
	y  = (window.get_screen_height() - get_y() - get_height() - (BORDER_WIDTH/2)) / window.get_screen_height();
	sx = get_width() / window.get_screen_width();
	sy = float( BORDER_WIDTH) / window.get_screen_height();
	orthographic_plane_.render( textures_[TEXTURE_BORDER], x, y, 1.0, sx, sy, 1.0, 0.0, 0.0, 90.0, 100);


	// The buttons then need to be applied to a plane and the plane then needs to be
	// manipulated to sit in the correct orthographic position.
}

//// FUNCTION - reset
// clear all the user-created data in preparation of a new module
void Macrobar::reset() {
	// Pre-conditions :- none
	assert( true);

	
}